function [N, locations, adjacency_matrix, badNodes, goodNodes, seed, step] = initialize_network(N,height,width,max_distance,seed, step, bad_ratio)

    locations = create_initial_locations(N, width, height, 1);
    
    adjacency_matrix = zeros(N,N);

    % only path loss
    distance = @(source,loc)( sqrt(sum((loc - repmat( source,size(loc,1),1 ) ).^2,2) ) );

    % initialize ajacency matrix
    for i=1:N
        distances = distance( locations(i,:),locations );
        adjacency_matrix(i,:) = distances <= max_distance & distances > 0;
    end
    
     % initialize bad nodes
    numberOfBadNodes = ceil(bad_ratio*N);
    badNodes = [];
    while length(badNodes) < numberOfBadNodes
        badNode = ceil(N * rand());
        if ~any(badNodes(:) == badNode)
            badNodes(end+1) = badNode
        end
    end
    
    fprintf('Bad nodes');
    badNodes;
    goodNodes = setdiff([1:N], badNodes);
    
    %graph1
%     for i=1:1:N
%         plot( locations(i,1), locations(i,2),'--rs','LineWidth',2,...
%             'MarkerEdgeColor','k',...
%             'MarkerFaceColor','g',...
%             'MarkerSize',10,...
%             'Tag','hi')
%     
%     
%         hold on;
%     end
%     grid on;
%     hold on;

    for i=1:length(goodNodes)
        plot( locations(goodNodes(i),1), locations(goodNodes(i),2),'--rs','LineWidth',2,...
            'MarkerEdgeColor','k',...
            'MarkerFaceColor','g',...
            'MarkerSize',10,...
            'Tag','hi')
    
   
        hold on;
    end
     for i=1:length(badNodes)
        plot( locations(badNodes(i),1), locations(badNodes(i),2),'--rs','LineWidth',2,...
            'MarkerEdgeColor','k',...
            'MarkerFaceColor','r',...
            'MarkerSize',10,...
            'Tag','hi')
    
    
        hold on;
    end
    grid on;
    hold on;

    %end graph1
    
    %graph2
    %DG = sparse(adjacency_matrix);
    %UG = tril(DG + DG');
    %view(biograph(DG,[],'ShowWeights','on'))

    %view(biograph(UG,[],'ShowArrows','off','ShowWeights','on'))
    %end graph2
end
